﻿Public Class DRUGACCOUNT
    Dim connect As CONDB = CONDB.NewConnection()

    Dim PROVIDER_Check As New PROVIDERSCLASS


    Private Sub DRUGACCOUNT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASDRGACC()

        DesignForm(Me)
        DesignGrid(MASDRGACCGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASDRGACC()
        Dim objSelectDataMasdrgacc As New masdrgacc
        Dim MASDRGACC As DataTable
        MASDRGACC = connect.GetTable(objSelectDataMasdrgacc.selectMasdrgacc_)
        MASDRGACCGrid.PrimaryGrid.DataSource = MASDRGACC
    End Sub

    Private Sub MASDRGACCGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASDRGACCGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสบัญชียา").Value() IsNot DBNull.Value Then
            DACCCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสบัญชียา").Value()
        Else
            DACCCODETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อบัญชียา").Value() IsNot DBNull.Value Then
            DACCNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อบัญชียา").Value()
        Else
            DACCNAMETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masdrgaccStatusChk.Checked = True
        Else
            masdrgaccStatusChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masdrgacc SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `dacccode` = '" & DACCCODETxt.Text & "' ;"

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMasdrgacc.Enabled = False
    End Sub

    Private Sub addMasdrgacc_Click(sender As Object, e As EventArgs) Handles addMasdrgacc.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If DACCNAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masdrgacc
                    objInsertData.DACCNAME_ = DACCNAMETxt.Text
                    objInsertData.STATUS_ = masdrgaccStatusChk.Checked
                    objInsertData.insertMasdrgaccData()

                    SelectDatagridMASDRGACC()

                    DACCCODETxt.Text = ""
                    DACCNAMETxt.Text = ""
                    masdrgaccStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasdrgacc_Click(sender As Object, e As EventArgs) Handles editMasdrgacc.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If DACCCODETxt.Text.ToString.Length > 0 And DACCNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลบัญชียาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masdrgacc
                        objEditData.DACCCODE_ = DACCCODETxt.Text
                        objEditData.DACCNAME_ = DACCNAMETxt.Text
                        objEditData.STATUS_ = masdrgaccStatusChk.Checked
                        objEditData.editMasdrgaccData()

                        SelectDatagridMASDRGACC()

                        DACCCODETxt.Text = ""
                        DACCNAMETxt.Text = ""
                        masdrgaccStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
                addMasdrgacc.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrgacc")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrgacc")
        nextform.ShowDialog()
    End Sub
End Class